#include <windows.h>
#include <stdio.h>

#include <state_machine.h>

#include <mTestUnit.h>

// state = -1     == STOP

enum
{
	MS_STATE_A,
	MS_STATE_B,
	MS_STATE_C,
	MS_STATE_D,
};

int S_a( void * param )
{
	printf( "state A\n" );
	Sleep( 500 );
	return MS_STATE_B;
}

int S_b( void * param )
{
	printf( "state B\n" );
	Sleep( 500 );
	return MS_STATE_C;
}

int S_c( void * param )
{
	printf( "state C\n" );
	Sleep( 500 );
	return MS_STATE_D;
}

int S_d( void * param )
{
	printf( "state D\n" );
	Sleep( 500 );
	return MS_STATE_A;
}

void T_state_machine( void * ptr )
{
	mTestCase * TestCase = (mTestCase *) ptr;

	StateMachine machine;

	state_machine_init( &machine );

	state_machine_add_state( &machine, MS_STATE_A, S_a, NULL ); 
	state_machine_add_state( &machine, MS_STATE_B, S_b, NULL );
	state_machine_add_state( &machine, MS_STATE_C, S_c, NULL );
	state_machine_add_state( &machine, MS_STATE_D, S_d, NULL );

	state_machine_set_state( &machine, MS_STATE_A );

	state_machine_start( &machine, 1 );

	printf( "Sleeping...\n");
	Sleep( 3000 );

	printf( "Pausing...\n");
	state_machine_pause( &machine );

	printf( "Paused...\n");

	printf( "Sleeping...\n");
	Sleep( 3000 );

	state_machine_set_state( &machine, MS_STATE_A );

	printf( "Resuming...\n");
	state_machine_resume( &machine );

	printf( "Sleeping...\n");
	Sleep( 3000 );

	state_machine_destroy( &machine );
}
